﻿using MesBSW.BLL.Role;
using MesBSW.DAL.RoleDB;
using MesBSW.Tools;
using Sunny.UI;
using System;

namespace MesBSW.View.Dialog.Role
{
    public partial class AddRoleDia : UIEditForm
    {

        private RoleInfoControler _my_ctrl = new RoleInfoControler();

        private BaseRoleModel role;

        public AddRoleDia()
        {
            InitializeComponent();
        }

        public AddRoleDia(BaseRoleModel role = null)
        {
            InitializeComponent();

            if (role != null)
            {
                this.role = role;
                InitDiaValue();
            }
            else
            {
                this.role = new BaseRoleModel();
            }
        }

        public BaseRoleModel Role
        {
            get
            {
                role.role_name = this.role_name.Text.ToString();
                role.des = this.des.Text.ToString();
                role.create_date = DateTime.Now;
                role.create_user = MainFrm.LoginUser.user_name;
                return role;
            }
        }

        private void InitDiaValue() 
        {
            this.number.Text = this.role.id.ToString();
            this.role_name.Text = this.role.role_name!=null ? this.role.role_name.ToString():"";
            this.des.Text = this.role.des != null ? this.role.des.ToString():"";
        }


        protected override bool CheckData()
        {
            return CheckEmpty(role_name, "请输入角色名称");
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            _my_ctrl.saveRoleInfo(Role);
            UIMessageBox.Show(SysTools.errMsg);
        }
    }
    
}
